package com.hzlj.position.locate.common.common;

import cn.hutool.core.date.DateUtil;
import com.hzlj.common.message.common.dto.message.MessageNoticeResultDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @author lifh
 * @date 2023/3/29 10:34
 **/
@Data
@Accessors(chain = true)
public class AbnWarningTrackDTO {
    /**
     * 对应的记录
     */
    private Object  record;
    /**
     * 平台通知矫正人员
     */
    private Notice toJzry;
    /**
     * 平台通知工作人员
     */
    private Notice toGzry;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Notice {
        private Boolean success;
        private String time;
        private String body;

        public static Notice parse(MessageNoticeResultDTO notice) {
            if (notice == null) {
                Notice instance = new Notice();
                instance.setSuccess(false);
                instance.setTime(DateUtil.formatDateTime(new Date()));
                return instance;
            }
            return new Notice(
                    !notice.isFail(),
                    notice.getCreateTime(),
                    notice.getBody()
            );
        }
    }
}
